package com.cyy.set;

import com.cyy.tree.RBTree;

/**
 * 使用红黑树实现Set JDK中的TreeSet也是使用红黑树来实现的
 * @author 会玩的洋洋
 * @since 2022-02-27
 * @param <E>
 */
public class TreeSet<E> implements Set<E> {
    private RBTree<E> rbTree = new RBTree<>();

    @Override
    public int size() {
        return rbTree.size();
    }

    @Override
    public boolean isEmpty() {
        return rbTree.isEmpty();
    }

    @Override
    public void clear() {
        rbTree.clear();
    }

    @Override
    public boolean contains(E element) {
        return rbTree.contains(element);
    }

    @Override
    public void add(E element) {
        rbTree.add(element);
    }

    @Override
    public void remove(E element) {
        rbTree.remove(element);
    }

    @Override
    public void traversal(Visitor<E> visitor) {
        rbTree.inorderTraversal(visitor);
    }
}
